//
//  main.cpp
//  构造函数与析构函数
//
//  Created by linjinzhu on 2017/7/11.
//  Copyright © 2017年 baidu. All rights reserved.
//

#include <iostream>

using namespace std;

class Line {
public:
    void setLength(double len);
    double getLength();
    Line();
    Line(double len);
    ~Line();
private:
    double length;
};

/// 构造函数1
Line::Line() {
    cout << "line created" << endl;
}

/// 构造函数2
// 使用
/**Line::Line(double len) {
    cout << "Line::Line line created" << endl;
    length = len;
}*/

/// 构造函数3
// 使用初始化列表来初始化字段,和上面的代参构造函数是等价的
Line::Line(double len):length(len) {
    cout << "Line::Line line created" << endl;
}

/// 析构函数
Line::~Line() {
    cout << this << "\tline deleted." << endl;
}

void Line::setLength(double len) {
    length = len;
}

double Line::getLength() {
    return length;
}

int main(int argc, const char * argv[]) {

    Line line(100);
    cout << line.getLength() << endl;

    Line line2;
    line2.setLength(10);
    cout << line2.getLength() << endl;

    return 0;
}
